package com.laymi._admin.${tableName};

import java.util.Map;

import com.laymi.common.model.${TableName};
import com.jfinal.kit.Kv;
import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Db;
import com.laymi.common._util.SqlKit;
import com.laymi.common._util.SqlUtil;

/**
 * ${TableName}Service
 */
public class ${TableName}Service {
	
	public static final ${TableName}Service me =new ${TableName}Service();
	private final ${TableName} dao = new ${TableName}().dao();
	
	/**
	 * 查询Tables
	 * @param map
	 * @param pageNumber
	 * @param pageSize
	 * @return
	 */
	public Kv searchPage(Map<String, String[]> map,Integer pageNumber,Integer pageSize){
		Kv jmap = SqlUtil.searchPage(new ${TableName}(), map,"*",pageNumber , pageSize);
		return jmap;
	}
	
	/**
	 * 删除一个
	 * @return 
	 */
	public boolean delOne( String id) {
		return Db.deleteById("${table_name}", id);
	}
	
	/**
	 * 批量删除
	 */
	public void delAll(String ids) {
		if (ids!=null&&ids.split(",").length > 0) {  // idList 有可能为空，不加判断会出异常
			StringBuilder sql = new StringBuilder("delete from ${table_name} where id in");
			SqlKit.joinIds2(ids.split(","), sql);
			Db.update(sql.toString());
		}
	}
	
	/**
	 * 状态控制
	 */
	public Ret activate(String status,String id) {
		if(status!=null&&!"".equals(status)){
			if("0".equals(status)){
				dao.findById(id)
				.setStatus("1").update();
				return Ret.ok("msg", "冻结成功");
			}else{
				dao.findById(id)
				.setStatus("0").update();
				return Ret.ok("msg", "激活成功");
			}
		}
		return null;
	}
	
	/**
	 * 根据id查询
	 */
	public ${TableName} findById(String id) {
		return dao.findById(id);
	}
	

}